﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using Rodunu.Movies.Data;
using Rodunu.Movies.Interfaces.Comments;

namespace Rodunu.Movies.Logic.Comments
{
    public class CommentsLogic : Repository<Contracts.Comments>, IComments
    {
        #region IComments Members

        public IList<Contracts.Comments> GetCommentsByUserMovie(long userMovieId)
        {
            ISession session = DBHelper.GetCurrentSession();
            return session.CreateCriteria(typeof(Contracts.Comments))
                                                     .Add(Expression.Eq("UserMovieId", userMovieId))
                                                     .List<Contracts.Comments>();
        }

        public IList<Contracts.Comments> GetRecentCommentsByUser(long userId)
        {
            ISession session = DBHelper.GetCurrentSession();
            return session.CreateCriteria(typeof(Contracts.Comments))
                                                     .Add(Expression.Eq("UserId", userId))
                                                     .AddOrder(new Order("DateAdded", false))
                                                     .SetMaxResults(5)
                                                     .List<Contracts.Comments>();
        }

        #endregion
    }
}
